package org.ktjiaoyu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import jakarta.annotation.Resource;
import org.ktjiaoyu.mapper.PermissionMapper;
import org.ktjiaoyu.pojo.Permission;
import org.ktjiaoyu.pojo.Role;
import org.ktjiaoyu.pojo.RolePermission;
import org.ktjiaoyu.service.RightService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RightServiceImpl extends ServiceImpl<PermissionMapper, Permission>
    implements RightService {

    @Resource
    PermissionMapper permissionMapper;
    @Override
    public List<Permission> getPermissionListByRoleId(Integer rid) {
        //根据用户角色查询权限集合
        List<Permission> permissions = permissionMapper.selectJoinList(Permission.class, new MPJLambdaWrapper<Permission>()
                .selectAll(Permission.class)
                .innerJoin(RolePermission.class, RolePermission::getPermission, Permission::getPermit)
                .eq(Role::getId, rid));

        return permissions;
    }

/*    select *
    from sys_user u
    ,sys_role r
      ,sys_role_right srr
      ,sys_right sr
    where 1=1
    and u.usr_role_id = r.role_id
    and srr.rf_role_id = r.role_id
    and srr.rf_right_code = sr.right_code
    and u.usr_id=2*/

}